package cn.net.yugu.doraemon.api.common.enums;

import java.util.Optional;

import lombok.Getter;

/**
 * @author xiangzr
 * @version 2023/08/01 20:54:57:57
 */
@Getter
public enum CommonRestResultCode implements IntegerEnum{
    OK_LEGACY(0, "成功"),
    INTERNAL_ERROR(1, "服务器内部错误"),
    PARAMETER_ERROR(2, "参数错误"),

    OK(200, "OK"),
    BAD_REQUEST(400, "Bad Request"),
    UNAUTHORIZED(401, "未验证身份"),
    FORBIDDEN(403, "未授权"),
    NOT_FOUND(404, "服务器找不到请求的资源"),
    UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
    LOCKED(423, "The resource that is being accessed is locked."),
    TOO_MANY_REQUESTS(429, " Too Many Requests. (\"rate limiting\")"),
    Internal_Server_Error(500, "Internal Server Error"),
    SERVICE_UNAVAILABLE(503, "Service Unavailable");

    private final Integer code;
    private final String desc;


    CommonRestResultCode(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static Optional<CommonRestResultCode> parseCode(Integer code) {
        return BaseEnum.of(values(), code);
    }
}
